#!/bin/bash -e
# ------------------------------------------------------
# ODROID
# ------------------------------------------------------
echo
echo "**********************************************************************"
echo "*                                                                    *"
echo "*              BUILDING Pi4J FOR THE 'Odroid' PLATFORM               *"
echo "*                                                                    *"
echo "**********************************************************************"
echo
WIRINGPI_PLATFORM=odroid

# build wiringPi
#export WIRINGPI_REPO=https://github.com/hardkernel/wiringPi.git
export WIRINGPI_REPO=https://github.com/Pi4J/wiringPi-Odroid
export WIRINGPI_BRANCH=master
export WIRINGPI_DIRECTORY=wiringPi
rm --recursive --force wiringPi
./wiringpi-build.sh $@

# compile the 'lib4j.so' JNI native shared library on the Raspberry Pi platform
echo
echo "==========================================="
echo "Building Pi4J JNI library (staticly linked)"
echo "==========================================="
echo
mkdir -p lib/$WIRINGPI_PLATFORM/static
make clean static TARGET=lib/$WIRINGPI_PLATFORM/static/libpi4j.so CARGS='-DWIRINGPI_SPI_SETUP_MODE_UNSUPPORTED' $@

echo
echo "=============================================="
echo "Building Pi4J JNI library (dynamically linked)"
echo "=============================================="
echo
mkdir -p lib/$WIRINGPI_PLATFORM/dynamic
make clean dynamic TARGET=lib/$WIRINGPI_PLATFORM/dynamic/libpi4j.so CARGS='-DWIRINGPI_SPI_SETUP_MODE_UNSUPPORTED' $@